package com.kupurui.asteacher.ui.index;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.StudentInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 学生详情
 * Created by Administrator on 2017/7/18.
 */

public class StudentDatailsAty extends BaseAty {


    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.imgv_head)
    SimpleDraweeView imgvHead;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_school_name)
    TextView tvSchoolName;
    @Bind(R.id.tv_grade)
    TextView tvGrade;
    @Bind(R.id.tv_class_name)
    TextView tvClassName;
    @Bind(R.id.tv_phone)
    TextView tvPhone;
    @Bind(R.id.tv_qq)
    TextView tvQq;
    @Bind(R.id.tv_student_errors)
    TextView tvStudentErrors;
    @Bind(R.id.tv_student_homework)
    TextView tvStudentHomework;
    @Bind(R.id.tv_student_examination)
    TextView tvStudentExamination;

    private String class_id = "";
    private String student_id = "";

    StudentInfo studentInfo;

    @Override
    public int getLayoutId() {
        return R.layout.student_datails_aty;
    }

    @Override
    public void initData() {
        if (getIntent().getExtras() != null) {
            class_id = getIntent().getStringExtra("class_id");
            student_id = getIntent().getStringExtra("student_id");
        }
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().studentDetail(class_id, student_id, this, 0);
    }

    @OnClick({R.id.iv_back, R.id.tv_student_homework, R.id.tv_student_errors, R.id.tv_student_examination})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_student_errors://错题本
                bundle.putString("sid",student_id);
                startActivity(MistakesAty.class, bundle);
                break;
            case R.id.tv_student_homework://作业完成情况
                bundle.putString("sid",student_id);
                startActivity(HomeworkCompletionkAty.class, bundle);
                break;
            case R.id.tv_student_examination://在线考试情况
                bundle.putString("sid",student_id);
                startActivity(ExamAboutAty.class, bundle);
                break;
        }
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what) {
            case 0:
                studentInfo = AppJsonUtil.getObject(result, StudentInfo.class);
                imgvHead.setImageURI(studentInfo.getImg());
                tvName.setText(studentInfo.getUsername());
                tvSchoolName.setText(studentInfo.getSchool());
                tvGrade.setText(studentInfo.getGrade());
                tvClassName.setText(studentInfo.getClass_name());
                tvPhone.setText(studentInfo.getPhone());
                tvQq.setText(studentInfo.getQq());
                break;
        }
        super.onSuccess(result, call, response, what);
    }


}
